package com.jwds.digital.bios.business.service.rule.impl;

import com.jwds.digital.bios.business.core.constants.RuleCodeConstant;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchParameterReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.FiveBasicInformationReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.BasicStockBinRespVO;
import com.jwds.digital.bios.business.service.rule.DispatchRuleSortInterface;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


//根据料仓料位高低
public class MaterialInventory implements DispatchRuleSortInterface {
    @Override
    public String getRuleCode() {
        return RuleCodeConstant.MATERIAL_INVENTORY;
    }

    @Override
    public List<DispatchParameterReqDTO> sortProcess(List<DispatchParameterReqDTO> dataList) {
        ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
        ArrayList<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOArrayList = new ArrayList<>();
        FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
        DispatchParameterReqDTO dispatchParameterReqDTO1 = new DispatchParameterReqDTO();
        for (DispatchParameterReqDTO dispatchParameterReqDTO : dataList) {
            for (FiveBasicInformationReqDTO fiveBasicInformationReqDTO1 : dispatchParameterReqDTO.getFlowList()) {
                List<BasicStockBinRespVO> collect = fiveBasicInformationReqDTO1.getOtherSlotList().stream()
                        .sorted(Comparator.comparing(BasicStockBinRespVO::getInventory))
                        .collect(Collectors.toList());
                // 起点仓
                fiveBasicInformationReqDTO.setOtherSlotList(collect);
                // 流程路线
                fiveBasicInformationReqDTO.setFlow(fiveBasicInformationReqDTO1.getFlow());
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(fiveBasicInformationReqDTO1.getDeviceCodeList());
                // 起点默认值
                fiveBasicInformationReqDTO.setDeviceTypeDefault(fiveBasicInformationReqDTO1.getDeviceTypeDefault());
                // 起点默认位置
                fiveBasicInformationReqDTO.setOtherSlotDefault(fiveBasicInformationReqDTO1.getOtherSlotDefault());
                fiveBasicInformationReqDTOArrayList.add(fiveBasicInformationReqDTO);
            }
            // 终点仓
            dispatchParameterReqDTO1.setSlot(dispatchParameterReqDTO.getSlot());
            // 终点设备
            dispatchParameterReqDTO1.setDeviceCodeList(dispatchParameterReqDTO.getDeviceCodeList());
            // 终点设备默认值
            dispatchParameterReqDTO1.setDeviceCodeDefault(dispatchParameterReqDTO.getDeviceCodeDefault());
            // 监控状态
            dispatchParameterReqDTO1.setState(dispatchParameterReqDTO.getState());
            // 仓标识
            dispatchParameterReqDTO1.setSlotIdentification(dispatchParameterReqDTO.getSlotIdentification());
            dispatchParameterReqDTO1.setFlowList(fiveBasicInformationReqDTOArrayList);
            parameterReqDTOArrayList.add(dispatchParameterReqDTO1);
        }
        return parameterReqDTOArrayList;
    }
}
